#include "blockQueue.hpp"
#include <iostream>
#include <unistd.h>

using namespace std;

const int NUM = 10000;

void* consume(void* bq)
{
    blockQueue<int>* blockQ = static_cast<blockQueue<int>*>(bq);
    while(true)
    {
        int good = blockQ->pop();
        cout << "consumer get a good, id:" << good << endl;
        //usleep(100);
        //sleep(1);
    }
}

void* produce(void* bq)
{
    blockQueue<int>* blockQ = static_cast<blockQueue<int>*>(bq);
    int cnt = 1;
    while(true)
    {
        blockQ->push(cnt++);
        //usleep(100);
        sleep(1);
    }
}

int main()
{
    blockQueue<int>* bq = new blockQueue<int>(5);
    pthread_t producer, consumer;
    pthread_create(&producer, nullptr, produce, (void*)bq);
    pthread_create(&consumer, nullptr, consume, (void*)bq);

    pthread_join(producer, nullptr);
    pthread_join(consumer, nullptr);
    return 0;
}